﻿using System;
using System.Collections.Generic;
using System.Text;
using TigerAndGoats.Control;
using TigerAndGoats.Framework;

namespace TigerAndGoats.Sprites
{
    public class GoatGroup: Piece
    {
        public GoatGroup()
        {
            this._image = null;
        }

        public override void PutUp(Action action = null)
        {
            if (GameControl.currentRound == GameControl.Round.Goats && GameControl.GoatsOnHand > 0)
            {
                List<Tuple<GraphNode, DestinationGoatGroup>> actualReachablePoints = new List<Tuple<GraphNode, DestinationGoatGroup>>();

                foreach (var graphNode in ChequerGraph.GetInstance().graphNodes)
                {
                    if (graphNode.Value.GetPiece() == Piece.Empty)
                    {
                        GraphNode reachableNode = graphNode.Value;
                        var reachablePoint = new DestinationGoatGroup() { FromPiece = this };
                        _reachableDestinations.Add(reachablePoint);
                        actualReachablePoints.Add(new Tuple<GraphNode, DestinationGoatGroup>(reachableNode, reachablePoint));
                    }
                }

                if (actualReachablePoints.Count > 0)
                {
                    base.PutUp(new Action(() =>
                    {
                        foreach (var pathPairTuple in actualReachablePoints)
                        {
                            pathPairTuple.Item1.SetPiece(pathPairTuple.Item2);
                        }
                    }));
                }
            }
        }
    }
}
